import  {defineStore} from 'pinia'

export const moduleUser=defineStore('userInfo',{
  state:()=>{
    return {
      address: JSON.parse(uni.getStorageSync('address') || '{}'),
      token:uni.getStorageSync('token') || '',
      userinfo:JSON.parse(uni.getStorageSync('userinfo') || '{}'),
      redirectInfo:null}
  },
  actions:{
    updateAddress(address){
      this.address=address
      this.saveAddressToStorage()
    },
    saveAddressToStorage() {
          uni.setStorageSync('address', JSON.stringify(this.address))
        },
    updateUserInfo(userinfo){
      this.userinfo=userinfo
      this.saveUserInfoToStorage()
    },
    saveUserInfoToStorage() {
        uni.setStorageSync('userinfo', JSON.stringify(this.userinfo))
      },
    updateToken(token){
      this.token=token
      this.saveTokenToStorage()
    },
      saveTokenToStorage() {
        uni.setStorageSync('token', this.token)
      },
      updateRedirectInfo(info){
        this.redirectInfo=info
      }
  },
  getters:{
     addstr(){
      if(!this.address.provinceName) return ''
      return this.address.provinceName+this.address.cityName+this.address.countyName+this.address.detailInfo
    }
  }
})